package kr.ac.konkuk.dblab.point.test.utils;

import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.HashSet;
import java.util.Set;

public class PointReader extends Reader {
	private BufferedReader reader;
	
	public PointReader(Reader reader) {
		if (reader instanceof BufferedReader) {
			this.reader = (BufferedReader)reader;
		} else {
			this.reader = new BufferedReader(reader);
		}
	}
	
	public Set<Point2D> readPoints() throws IOException {
		String line;
		Set<Point2D> points = new HashSet<Point2D>();
		while ((line = this.reader.readLine()) != null) {
			String []ps = line.split(",");
			double x = Double.parseDouble(ps[0]), y = Double.parseDouble(ps[1]);
			points.add(new Point2D.Double(x, y));
		}
		
		return points;
	}

	public int read(char[] cbuf, int off, int len) throws IOException {
		return reader.read(cbuf, off, len);
	}

	public void close() throws IOException {
		reader.close();
	}
}
